import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { CacheModule } from '@nestjs/cache-manager';

@Module({
  imports: [
    JwtModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (config: ConfigService) => {
        return {
          //设置token在.env文件里面的密钥
          secret: config.get('TOKEN_SECRET'),
          //设置token有效期时间
          signOptions: { expiresIn: '20d' },
        };
      },
    }),
    CacheModule.register({
      isGlobal: true,
    }),
  ],

  controllers: [AuthController],
  providers: [AuthService],
})
export class AuthModule {}
